<?php

class Application_Form_Signup extends Zend_Form
{

    public function init() {
    	
        $this->setDecorators(array(
			'FormElements',
			array('HtmlTag', array('tag' => 'table')),
			'Form',
		));
		//define the customed decorators for labels and input box, changing them into tables
		$customElementDecorators = array(
            'ViewHelper',
            'Description',
            'Errors',
            array(array('data' => 'HtmlTag'),array('tag' => 'td')),
            array('Label', array('tag' => 'td','id'=>'zendlabel')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr')),
        );
        
		//set the form id to signupForm.
		$this->setAttrib('id', 'signupform');
		
		//user type, 1 means common user, 2 means admin role user.
		$userType = $this->createElement('hidden','user_type');
		//face book token.
		$fbaccount = $this->createElement('hidden','fb_account');
		
		//hidden input. The id information is for finding the user information easily. Match to account in database.
		$account = $this->createElement('text','account');
		$account->setLabel('Email account: *')->setRequired(true)->setDecorators($customElementDecorators);
		
		//name element. Match to name in database.
		$name = $this->createElement('text','name');
		$name->setLabel('Name: *')->setRequired(true)
				  ->addValidator('NotEmpty')
                  ->setDecorators($customElementDecorators);

        //old password, used by edit action.
		$currentPassword = $this->createElement('password','currentPassword');
		$currentPassword->setLabel('Current Password: *')
                        ->setDecorators($customElementDecorators);
				 		  
		//member_password element. Match to member_password in database.
		$password = $this->createElement('password','password');
		$password->setLabel('Password: *')->setRequired(true)
				 ->addValidator('NotEmpty')
                        ->setDecorators($customElementDecorators);

		//it should be equal to password and is not write to database.
		$confirmPassword = $this->createElement('password','confirmPassword');
		$confirmPassword->setLabel('Confirm Password: *')->setRequired(true)
						->addValidator('NotEmpty')
                        ->setDecorators($customElementDecorators);
		
		//phone element. Match to tel in database.
		$tel = $this->createElement('text','tel');
		$tel->setLabel('Tel: ')->setRequired(false)
			  ->addValidator('int')
                        ->setDecorators($customElementDecorators);
		
		//birthday element. Match to birthday in database.
		//it uses jquery datepicker plugin.
		$birthday = $this->createElement('text','birthday');
		$birthday->setLabel('Birthday: ')->setRequired(false)
				 ->addValidator('Date', 'yyyy-MM-dd')
                        ->setDecorators($customElementDecorators);
		
		//address element. Match to address in database.
		$address = $this->createElement('text','address');
		$address->setLabel('Address: ')->setRequired(false)
                        ->setDecorators($customElementDecorators);

        //university element. Match to university in database.
		$university = $this->createElement('text','university');
		$university->setLabel('University: ')->setRequired(false)
                        ->setDecorators($customElementDecorators);
		
        //major element. Match to major in database.                
		$major = $this->createElement('text','major');
		$major->setLabel('Major: ')->setRequired(false)
                        ->setDecorators($customElementDecorators);
		
        //submit botton      
		$register = $this->createElement('submit','register');
		$register->setLabel('Sign up')->setIgnore(true)
                        ->setDecorators(array(
                            'ViewHelper',
                            array(array('data' => 'HtmlTag'), array('tag' => 'td')),
                            array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
                            array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
                    ));
		//transfer the data to action.
		$this->addElements(array(
								$userType,
								$fbaccount,
								$account,
								$name,
								$currentPassword,
								$password,
								$confirmPassword,
								$birthday,
								$address,
								$tel,
								$password,
								$university,
								$major,
								$register
								));
		}
		

}

